package com.xcexample.adclasscard.main

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.LinearLayout
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.xcexample.adclasscard.R
import com.xcexample.adclasscard.main.ImageAdapter.BannerViewHolder
import com.youth.banner.adapter.BannerAdapter


/**
 * 自定义布局，下面是常见的图片样式，更多实现可以看demo，可以自己随意发挥
 */
class ImageAdapter(datas: ArrayList<String>) : BannerAdapter<String, BannerViewHolder>(datas) {
    //创建ViewHolder，可以用viewType这个字段来区分不同的ViewHolder
    override fun onCreateHolder(parent: ViewGroup, viewType: Int): BannerViewHolder {
        var view= LayoutInflater.from(parent.context).inflate(R.layout.play_item_image,parent,false)
        return BannerViewHolder(view)
    }

    override fun onBindView(holder: BannerViewHolder?, data: String, position: Int, size: Int) {
        if (holder != null) {
            Glide.with(holder.imageView.context)
                .load(data).into(holder.imageView)
        }
    }

    class BannerViewHolder(view: View) : RecyclerView.ViewHolder(view) {
        //        var imageView: ImageView = view as ImageView
        var imageView: ImageView = view.findViewById(R.id.image)
    }

}

